<template>
  <!-- 底部部分 -->
  <footer class="footer" v-if="list.length > 0">
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong
      >剩余</span
    >
    <ul class="filters">
      <li>
        <a
          @click.prevent="filter('all')"
          :class="{ selected: type === 'all' }"
          href="#/"
          >全部</a
        >
      </li>
      <li>
        <a
          @click.prevent="filter('active')"
          :class="{ selected: type === 'active' }"
          href="#/active"
          >进行中</a
        >
      </li>
      <li>
        <a
          @click="filter('completed')"
          :class="{ selected: type === 'completed' }"
          href="#/completed"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clear">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
  },

  data() {
    return {
      type: 'all',
    }
  },

  computed: {
    leftCount() {
      // 获取所有未完成的任务的数量
      return this.list.filter((item) => item.isDone === false).length
    },
    isshowCler() {
      // 如果list中有一个或者多个完成的任务，就应该显示
      return this.list.some((item) => item.isDone === false)
    },
  },
  methods: {
    clear() {
      // 清空已经完成的任务  过滤，保留未完成的任务
      this.$emit('clear')
    },
    filter(type) {
      // this.type = type
      this.$emit('changeType', type)
    },
  },
}
</script>

<style></style>
